<template>
  <div>
    <a-modal v-model:open="open" title="案例体验统计" :footer="null" style="height: 354px" @cancel="cancel">
      <div class="case-statistics">
        <div class="not">
          <div class="title">
            <span>{{ experienced.length }}</span
            >人未体验
          </div>
          <div v-for="(item, index) in experienced" :key="index" class="content">
            <div class="name">{{ item.userName }}({{ item.userNum }})</div>
          </div>
        </div>
        <div class="line"></div>
        <div class="had">
          <div class="title">
            <span>{{ experience.length }}</span
            >人已体验
          </div>
          <div v-for="(item, index) in experience" :key="index" class="content">
            <div class="name">{{ item.userName }}({{ item.userNum }})</div>
          </div>
        </div>
      </div>
    </a-modal>
  </div>
</template>

<script setup lang="ts">
  import { message } from 'ant-design-vue'
  import { ref, watch } from 'vue'

  import { learningTasksManageApi } from '@/services/api'
  const open = ref(false)

  const props = defineProps({
    id: {
      type: String,
      default: ''
    },
    orgId: {
      type: String,
      default: ''
    },
    caseStatisticsFlag: {
      type: Boolean,
      default: false
    }
  })
  const experienced = ref<any>([])
  const experience = ref<any>([])

  // 获取统计数据
  const initList = async (): Promise<void> => {
    console.log('56666666666:', props.id, props.orgId)

    try {
      const { data } = await learningTasksManageApi.caseStatisticsList({
        id: props.id,
        orgId: props.orgId
      })
      experienced.value = data.experienced
      experience.value = data.experience
      console.log(experienced.value, experience.value)
    } catch (error) {
      message.error('失败')
    }
  }

  const cancel = () => {
    open.value = false
  }

  watch(
    () => open.value,
    () => {
      initList()
    }
  )

  defineExpose({
    open: () => {
      open.value = true
      // initList()
    }
  })
</script>

<style lang="less" scoped>
  :deep(.ant-modal .ant-modal-body) {
    padding: 0 !important;
  }

  .case-statistics {
    display: flex;
    justify-content: space-around;
    height: 100%;

    .line {
      width: 1px;
      // height: 354px;
      background-color: rgba(0, 0, 0, 0.05);
    }

    .had,
    .not {
      padding: 20px 16px;
      width: 100%;

      .title {
        margin-bottom: 20px;
        font-size: 12px;
        color: rgba(21, 23, 27, 0.95);
        line-height: 20px;

        span {
          font-weight: 700;
          font-size: 16px;
        }
      }

      .content {
        display: flex;

        .name {
          margin-bottom: 12px;
          font-size: 14px;
          color: rgba(17, 22, 31, 0.75);
          line-height: 22px;
        }
      }
    }
  }
</style>
